import {request} from '@/utils/request'
import type { HbtInstanceOperQuery, HbtInstanceOper, HbtInstanceApprove } from '@/types/workflow/oper'
import type { HbtPagedResult } from '@/types/common'

// 获取工作流实例操作记录分页列表
export function getInstanceOperList(query: HbtInstanceOperQuery) {
  return request<HbtPagedResult<HbtInstanceOper>>({
    url: '/api/HbtInstanceOper/list',
    method: 'get',
    params: query
  })
}

/**
 * 根据ID获取工作流实例操作
 */
export function getInstanceOperById(instanceOperId: string) {
  return request<HbtInstanceOper>({
    url: `/api/HbtInstanceOper/${instanceOperId}`,
    method: 'get'
  })
}


/**
 * 删除工作流实例操作
 */
export function deleteInstanceOper(instanceOperId: string) {
  return request<boolean>({
    url: `/api/HbtInstanceOper/${instanceOperId}`,
    method: 'delete'
  })
}

/**
 * 批量删除工作流实例操作
 */
export function batchDeleteInstanceOper(instanceOperIds: string[]) {
  return request<boolean>({
    url: '/api/HbtInstanceOper/batch',
    method: 'delete',
    data: instanceOperIds
  })
}

// 工作流审批
export function approveInstance(data: HbtInstanceApprove) {
  return request<boolean>({
    url: '/api/HbtInstanceOper/approve',
    method: 'post',
    data
  })
}


// 导出工作流实例操作记录
export function exportInstanceOper(query: HbtInstanceOperQuery) {
  return request<Blob>({
    url: '/api/HbtInstanceOper/export',
    method: 'get',
    params: query,
    responseType: 'blob'
  })
}


// 获取工作流实例操作记录选项列表
export function getInstanceOperOptions() {
  return request<{ label: string; value: number }[]>({
    url: '/api/HbtInstanceOper/options',
    method: 'get'
  })
}

// 获取我的操作记录列表
export function getMyInstanceOperList(query: HbtInstanceOperQuery) {
  return request<HbtPagedResult<HbtInstanceOper>>({
    url: '/api/HbtInstanceOper/my',
    method: 'get',
    params: query
  })
}

/**
 * 根据实例ID获取操作列表
 */
export function getInstanceOperListByInstance(instanceId: string, query: HbtInstanceOperQuery) {
  return request<HbtPagedResult<HbtInstanceOper>>({
    url: `/api/HbtInstanceOper/instance/${instanceId}`,
    method: 'get',
    params: query
  })
}
